package part2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * Java5Ex6 Genericized version of Java5Ex2
 *   Example with wildcard for type parameters
 * @author tony
 *
 */

public class Java5Ex7 {

	void printAll(List<?> list) {
		/*
		 * Iterator for loop
		 */
		for (Iterator<?> i = list.iterator(); i.hasNext(); )
			System.out.println( i.next().toString() );
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		/*
		 * Set up an Array of Strings
		 */
		List<String> list1 = new ArrayList<String>();
		list1.add("Hello");
		list1.add( "1" );
		list1.add( "100" );
		list1.add( "Goodbye" );

		Java5Ex7 obj = new Java5Ex7();
		obj.printAll( list1 );
		
		/*
		 * Set up a Linked List of Integers
		 */
		List<Integer> list2 = new LinkedList<Integer>();
		list2.add(  -34 );
		list2.add( 1026 );
		list2.add( -113 );
		list2.add(    0 );

		// The same method can also print a list of integers
		obj.printAll( list2 );
	}
}
